class ManageController < ApplicationController
  
  def index
    @gadget = Gadget.find(:first)
    @categories = Category.find(:all)
  end
  
  
  def load_gadget_info
    @gadget = Gadget.find(params[:id])
    render :partial => 'gadgets/gadget_info'
  end
  
  
  def edit_gadget_spec
    @gadget = Gadget.find(params[:id])
    filename = @gadget.spec_url.split("/").last 
    my_file = File.new("public/gadget_specs/#{filename}", 'r')
    @gadget_spec_content = my_file.read
    my_file.close
    render :partial=>'gadget_editor'
  end
  
  
  def save_gadget_spec
    @gadget = Gadget.find(params[:id])
    filename = @gadget.spec_url.split("/").last
    render :partial => 'gadgets/gadget_info'
  end
  
  
  def publish_gadget
    @gadget = Gadget.find(params[:id])
    @gadget.update_attribute('published', true)
    render :text=>@gadget.id.to_s
  end
  
  
  def unpublish_gadget
    @gadget = Gadget.find(params[:id])
    @gadget.update_attribute('published', false)
    render :text=>@gadget.id.to_s
  end
  
end
